package model;

import java.awt.Color;
import java.util.Observable;
import java.util.Observer;

public class HumanPlayer extends AbstractPlayer implements Observer {

	private static final String description = "Human";
	private Observable o;
	private int selectedCol;

	public HumanPlayer(Color color, Observable o) {
		super(color, description);
		this.o = o;
		selectedCol = -1;
	}


	/**
	 * abilito la registrazione per l'ascolto dell'evento di selezione colonna
	 */
	@Override
	public void takeTurn(Slot[][] board) {
		super.takeTurn(board);
		selectedCol = -1;
		o.addObserver(this);
	}

	@Override
	public void update(Observable o, Object arg) {
		if (turnToPlay) {
			// colonna in cui inserire
			int col = (int) arg;
			if (positionIsValid(col,board)) {
				
				o.deleteObserver(this);
				selectedCol = col;
			}
		}
	}


	@Override
	public int executeMove() {
		return selectedCol;

	}

}
